package com.sikulifang.bank.simulation.controller;

import cn.hutool.core.lang.Dict;
import com.sikulifang.bank.simulation.service.IAccountService;
import com.sikulifang.bank.simulation.util.R;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * ClassName AccountController
 * Description 账号
 *
 * @author Yat
 * Date 2023/6/2 9:27
 * version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/api/account")
public class AccountController extends AbstractController<IAccountService> {

    /**
     * Description: 查询所有账号，不分页
     * <p>
     * Date: 2023年6月12日, 0012 17:06
     *
     * @param account 排除的账号
     * @return {@link Dict}
     */
    @GetMapping("/find/all")
    public Dict findAll(@RequestParam(required = false) String account) {
        return service.findAll(account);
    }

    /**
     * 根据银行名称查询对应的账号
     *
     * @param bankName 银行名称
     */
    @SneakyThrows
    @GetMapping("/find/name/by/bank")
    public R<List<String>> findAccountNameByBankName(@RequestParam(required = false) String bankName) {
        return R.ok(service.findAccountNameByBankName(bankName));
    }

    /**
     * 根据银行名称查询对应的账号
     *
     * @param accountName 账号名称
     */
    @SneakyThrows
    @GetMapping("/find/no/by/name")
    public R<List<String>> findAccountNoByBankName(
            @RequestParam(required = false) String accountName,
            @RequestParam(required = false) String bankName
    ) {
        return R.ok(service.findAccountNoByBankName(accountName, bankName));
    }

    /**
     * Description: 充值
     * <p>
     * Date: 2023年6月9日, 0009 17:19
     *
     * @param id    账号
     * @param money 充值的金额
     */
    @SneakyThrows
    @GetMapping("/recharge/{id}")
    public R<String> recharge(@PathVariable String id, BigDecimal money) {
        service.recharge(id, money);
        return R.ok("充值成功");
    }

}
